package lab02.test23;


import java.util.*;
import java.text.*;

public class Test23 {
    public static void main(String[] args) throws ParseException {

        SimpleDateFormat now = new SimpleDateFormat("MM-dd");//设置日期格式


        String a = now.format(new Date());   //获取当前时间
        Date a1 = now.parse(a);  //将String类型转化为日期型

        SimpleDateFormat input = new SimpleDateFormat("MMdd");//设置日期格式
        Scanner bi = new Scanner(System.in);    //创建一个对象
        System.out.print("请输入你的生日：");
        String birth = bi.next();   //输入生日
        Date b1 = input.parse(birth);  //将String类型转化为日期型


        Calendar cal1 = Calendar.getInstance(); //可以对每个时间域单独修改
        cal1.setTime(new Date());


        //获取今年的年份
        int year1 = cal1.get(Calendar.YEAR);

        //计算两个时间相差的天数，用
        long daysBetween = (b1.getTime() - a1.getTime()) / (3600 * 24 * 1000);

        if (daysBetween <= 0) {

            if ((year1 + 1) % 4 == 0 && (year1 + 1) % 100 != 0 || (year1 + 1) % 400 == 0) {
                daysBetween += 366;
            } else daysBetween += 365;

        }

        System.out.println("现在" + "(" + now.format(new Date()) + ")" + "距你下次生日还有" + daysBetween + " 天");

        //求生日与当前日期相隔天数的余数，若为0则与当前日期同样为星期几，依次往后推
        int j = (int) daysBetween % 7;
        int i = cal1.get(Calendar.DAY_OF_WEEK);
        if (i == 1) {
            System.out.println("今天是星期日");
        } else {
            System.out.println("今天是星期" + (i - 1));
        }
        if ((i + j - 1) % 7 == 0) {
            System.out.println("当天是星期日");
        } else
            System.out.println("当天是星期" + (i + j - 1) % 7);


    }
}
